package com.distribute.application.manage.agents;

import java.util.*;
import java.io.File;

import com.distribute.framework.core.web.helper.Utils;
import com.distribute.framework.core.lang.*;
import com.distribute.framework.core.web.node.Export;
import com.distribute.framework.core.lang.Protocol.BeanFormat;
import com.distribute.framework.core.util.Function;
import com.distribute.framework.core.web.util.*;

import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;

import com.distribute.framework.model.*;
import com.distribute.application.api.utils.WeiXinAccessTokenUtil;
import com.distribute.application.api.utils.WxMiniQrCodeUtil;
import com.distribute.application.manage.*;
/************CTRL_CODE_INPORT************/
/************CTRL_CODE_INPORT************/

/**
 * 代理卡配置的Controller
 * @author 飞啊飘啊
 */
@SuppressWarnings({"unchecked","rawtypes"})
@flag("AgentConf")
@RestController
@Component(value="manage.agents.agentconfController")
public class AgentconfController{
	
	@flag("stuct")
	@RequestMapping("/manage/agents/agentconf.list.do")
  	public Protocol list() {
  		try{
  			Protocol protocol = Protocol.create(true,null);
  			setFormDataInfo(protocol,null,null);
  			//处理页面的视图数据，比如显示哪些列，自定义显示列等
			ActionHelper.doPageViewFields(AgentConf.class);
  			Map<String,Object> params = setDefaultSort(ActionHelper.getQueryFormParams(AgentConf.class));
			protocol.set("PARAMS",ActionHelper.getQueryFormParams(AgentConf.class));
			protocol.set("fields", Utils.getRequest("fields"));
			Integer iPage = Utils.getInteger("page", 0);
			Integer iSize = Utils.getInteger("size",16);
			params.put("merchant",LoginHelper.getLogin().getId());
			/************CTRL_BEFORE_LIST************/
			/************CTRL_BEFORE_LIST************/
			Page page = AgentConf.page(iPage,iSize,params);//调用获取分页
	    	protocol.setPage(page,new BeanFormat<AgentConf>(){
				public Map format(AgentConf t) {
					return t.toJSON();
				}
			});
			/************CTRL_AFTER_LIST************/
			/************CTRL_AFTER_LIST************/
			return protocol;
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	@RequestMapping("/manage/agents/agentconf.export.do")
  	public Protocol export(HttpServletResponse response) {
  		try{
  			Protocol protocol = Protocol.create(true,null);
  			setFormDataInfo(protocol,null,null);
  			//处理页面的视图数据，比如显示哪些列，自定义显示列等
			ActionHelper.doPageViewFields(AgentConf.class);
  			Map<String,Object> params = setDefaultSort(ActionHelper.getQueryFormParams(AgentConf.class));
  			params.put("idIn", Utils.getString("ids"));
			Integer iPage = Utils.getInteger("page", 0);
			Integer iSize = Utils.getInteger("size",16);
			params.put("merchant",LoginHelper.getLogin().getId());
			/************CTRL_BEFORE_EXPORT************/
			/************CTRL_BEFORE_EXPORT************/
			final Map<String, Object> finalParams = params;
			//调用lazy3q.jar中的导出功能
			//参数说明：(这次导出多少条数据，到数据库查的时候一次查多少条，当前所在第几页,处理器，对应的模型类,要导出哪些字段)
			Utils.export(AgentConf.count(params).intValue(), 100, 0 , new Export(){//new Export这个类，他会根据参数分次查询，边查边写，目的只有一个，就是为了避免把大量的数据放在内存中
				@Override //重载实现Export的getPage方法，Export会分多次调用这个方法
				public Page getPage(Integer page, int size) {//这时的page和size是Export转化过后的当前页，每页查询数					
					return AgentConf.getAgentConfPage(page, size, finalParams);
				}
			}, AgentConf.class, Utils.getString("fields").split(","));
			/************CTRL_AFTER_EXPORT************/
			/************CTRL_AFTER_EXPORT************/
			return null;
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	
  	@flag("stuct")
  	@RequestMapping("/manage/agents/agentconf.get.do")
  	public Protocol get() {
  		try{
  			Protocol protocol = Protocol.create(true,null).set("agentConf",new HashMap());
  			AgentConf agentConf = Utils.getObject("", AgentConf.class);
  			if(agentConf!=null){
				protocol.set("agentConf",agentConf.toJSON());
			}
			Long id=Utils.or(Utils.getLong("id"),Utils.getLong("key"));
			String edittype = Utils.getString("edittype");
			if(id==null){
				setFormDataInfo(protocol,edittype,null);
				return protocol.reset(false,null,"args-id-null");
			}			
			agentConf=AgentConf.where.id(id).get();
			if(agentConf==null){
				return protocol.reset(false,"数据不存在","data-not-exist");
			}
			setFormDataInfo(protocol,edittype,agentConf);
			if(agentConf.getMerchant().longValue()!=LoginHelper.getLogin().getId().longValue()){
				protocol.reset(false,"没有权限访问数据","host-no-mate");
				agentConf=null;
			}
			protocol.set("agentConf",agentConf.toJSON());
			/************CTRL_CODE_GET************/
			/************CTRL_CODE_GET************/
			return protocol;
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	
  	
  	@limitVal(2)//查看权限
  	@RequestMapping("/manage/agents/agentconf.insert.do")
  	public Protocol insert() {
  		try{
			final String requestToken = Utils.getString("agentConfToken");
			final Date lastToken = Utils.getSession(requestToken);
			if(lastToken==null || (new Date().getTime()-lastToken.getTime())>10000){
				if(requestToken!=null)Utils.setSession(requestToken,new Date());//放入Token时间戳	
				AgentConf.execute(new Function(){
					public <T> T execute(Object... arg0){
						/************CTRL_BEFOR_INSERT************/
						/************CTRL_BEFOR_INSERT************/
						AgentConf agentConf = Utils.getObject("agentConf", AgentConf.class);
						//批量插入处理
						String vValue = ""+(agentConf.getName()==null?"":agentConf.getName());
						String sArray[]={""+vValue};
						if(vValue.startsWith("[*]")){
							vValue=vValue.replace("[*]","");
							sArray=vValue.split("[\\s|\u3000|\\u00a0|,]+");		
						}
						for(String sItem:sArray){
							if(!Utils.empty(sItem))
							agentConf.setName(String.valueOf(sItem));
							//设置默认值
							setDefaultValue(agentConf,"insert");
							agentConf.setMerchant(LoginHelper.getLogin().getId());
								/************CTRL_BEFORE_ADD************/
								/************CTRL_BEFORE_ADD************/
							AgentConf.saveAgentConf(agentConf);	
								/************CTRL_AFTER_ADD************/
								/************CTRL_AFTER_ADD************/
						}
						//记录操作日志
						LoggerHelper.writeLog(AgentConf.class,"add","添加了[代理卡配置]["+agentConf.getName()+"]",LoginHelper.getUserId(), agentConf,agentConf.getId());
						return null;
					}
				});
				
			}else{
				throw new DefineException("repeat-submit-error","对不起，请勿重复提交"+(10-((new Date().getTime()-lastToken.getTime())/1000))+"秒后再试");
			}
			/************CTRL_AFTER_INSERT************/
			/************CTRL_AFTER_INSERT************/
			return Protocol.create(true,"添加[代理卡配置]数据成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	
  	
  	@limitVal(4)//修改权限
  	@RequestMapping("/manage/agents/agentconf.update.do")
  	public Protocol update() {
  		try{
			final String requestToken = Utils.getString("agentConfToken");
			final Date lastToken = Utils.getSession(requestToken);
			if(lastToken==null || (new Date().getTime()-lastToken.getTime())>10000){
				if(requestToken!=null)Utils.setSession(requestToken,new Date());//放入Token时间戳	
				AgentConf.execute(new Function(){
					public <T> T execute(Object... arg0){
						/************CTRL_BEFOR_UPDATE************/
						/************CTRL_BEFOR_UPDATE************/
						AgentConf agentConf = Utils.getObject("agentConf", AgentConf.class);
						AgentConf oldAgentConf = null;
						String PARAMS = Utils.getString("PARAMS");
						String ids=Utils.getString("ids");
						if(!Utils.empty(PARAMS)){//根据查询条件批量更新
							Map params = Utils.eval(PARAMS);
							params.put("confirm", 1);
							params.put("definex","1=1");
							agentConf.setMerchant(LoginHelper.getLogin().getId());
							
							AgentConf.updateAgentConfByConfirm(ActionHelper.getSetValuesFromModel(agentConf), params);
							LoggerHelper.writeLog(AgentConf.class, "update", 
										"批量修改了[代理卡配置]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(null,agentConf,false)
										,null);
							/************CTRL_UPDATE_BY_PARAMS************/
							/************CTRL_UPDATE_BY_PARAMS************/
						}else if(!Utils.empty(ids)){//根据ids批量更新
							Map params = new HashMap();
							params.put("idIn",ids);
							params.put("confirm", 1);
							params.put("definex","1=1");
							AgentConf.updateAgentConfByConfirm(ActionHelper.getSetValuesFromModel(agentConf), params);
							LoggerHelper.writeLog(AgentConf.class, "update", 
										"批量修改了[代理卡配置]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(null,agentConf,false)
										,null);
							/************CTRL_UPDATE_BY_IDS************/
							/************CTRL_UPDATE_BY_IDS************/
						}else{
							if(Utils.empty(Utils.getString("all"))){//修改对象非空的字段
								oldAgentConf=AgentConf.where.id(agentConf.getId()).get();
								if(oldAgentConf==null){
									throw new DefineException("对不起，你没有权限修改当前数据");
								}
								
								AgentConf.updateAgentConf$NotNull(agentConf);
								LoggerHelper.writeLog(AgentConf.class, "update", 
										"修改了[代理卡配置]["+oldAgentConf.getName()+"]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(oldAgentConf, agentConf,false)
										,agentConf.getId());
								/************CTRL_UPDATE_NOT_NULL************/
								/************CTRL_UPDATE_NOT_NULL************/
							}else{//修改对象全部字段
								oldAgentConf=AgentConf.where.id(agentConf.getId()).get();
								if(oldAgentConf==null){
									throw new DefineException("对不起，你没有权限修改当前数据");
								}
								//设置默认值
								agentConf.setUpdateTime(oldAgentConf.getUpdateTime());	
								agentConf.setAddTime(oldAgentConf.getAddTime());	
								//设置默认值
								setDefaultValue(agentConf,"update");
								
								//从oldAgentConf同步agentConf未set过的值
								agentConf.mergeSet(oldAgentConf);
										
								AgentConf.updateAgentConf(agentConf);
								LoggerHelper.writeLog(AgentConf.class, "update", 
										"修改了[代理卡配置]["+oldAgentConf.getName()+"]",
										LoginHelper.getUserId(),LoggerHelper.getUpdateDescription(oldAgentConf, agentConf,true)
										,agentConf.getId());
								/************CTRL_UPDATE_ALL************/
								/************CTRL_UPDATE_ALL************/
							}
						}
						/************CTRL_CODE_UPDATE************/
						/************CTRL_CODE_UPDATE************/
						return null;
					}
				});
				
			}else{
				throw new DefineException("repeat-submit-error","对不起，请勿重复提交"+(10-((new Date().getTime()-lastToken.getTime())/1000))+"秒后再试");
			}
			/************CTRL_AFTER_UPDATE************/
			/************CTRL_AFTER_UPDATE************/
			return Protocol.create(true,"修改[代理卡配置]数据成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}
  	
  	@limitVal(8)//删除权限
  	@RequestMapping("/manage/agents/agentconf.delete.do")
  	public Protocol delete() {
  		try{
			AgentConf.execute(new Function(){
				public <T> T execute(Object... arg0){
					Long pid=Utils.getLong("id");
					Long[] ids=new Long[]{pid};
					String strIds=Utils.getString( "ids");
					if(!Utils.empty(strIds) && !strIds.trim().equals("")){//批量删除
						String[] array = strIds.split(",");
						ids=new Long[array.length];
						for(int i=0;i<array.length;i++)
							ids[i]=Long.valueOf(array[i]);
					}
					if(ids.length==0){
						throw new DefineException("args-id-null","参数错误");
					}
					for(Long id:ids){
						AgentConf agentConf = null;
						agentConf=AgentConf.where.id(id).get();
						if(agentConf==null){
							throw new DefineException("对不起，你没有权限修改当前数据");
						}
						AgentConf.delete(id);						
						if(agentConf!=null)//记录操作日志
							LoggerHelper.writeLog(AgentConf.class,"del","删除了[代理卡配置]["+agentConf.getName()+"]",LoginHelper.getUserId(), agentConf);
						/************CTRL_CODE_DEL************/
						/************CTRL_CODE_DEL************/
					}
					return null;
				}
			});
			return Protocol.create(true,"删除操作成功");
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
  	}

	@RequestMapping("/manage/agents/agentconf.query.do")
	public Protocol query(){
		try{
			Map<String,Object> params = setDefaultSort(ActionHelper.getQueryFormParams(AgentConf.class));
			params.put("merchant",LoginHelper.getLogin().getId());
			
			String strTerm=Utils.getString("value");//智能搜索时的参数，一般都是主键后面那个字段
			if(!Utils.empty(strTerm)){
				if(strTerm.toLowerCase().startsWith("id:"))//如果查询条件以id:开头，则按ID查询
					params.put("id", strTerm.toLowerCase().replaceFirst("id:", ""));					
				else//按标识查询，模糊查询请带%
				{
					String strDefinex = "";
					strDefinex+=" or name like '%"+strTerm.replaceAll("'", "''")+"%'";
					strDefinex="(2=1 "+strDefinex+")";
					params.put("definex",strDefinex);
				}
			}
			
			Integer iSize = Utils.getInteger("size",10);
			/************CTRL_CODE_QUERY************/
			/************CTRL_CODE_QUERY************/
			
			List<AgentConf> list = AgentConf.page(0,iSize,params).getResult();
			
			Boolean bObject=Utils.getBoolean("object",false);//是否需要整个数据对象
			List<Map> result = new java.util.ArrayList();
			for(AgentConf agentConf:list){
				Map map = new HashMap();
				map.put("key",agentConf.getId().toString());
				map.put("value", Utils.js(agentConf.getKeyValue()));
				if(bObject==true){
					map.put("object",agentConf);
				}
				result.add(map);
			}
			/************CTRL_AFTER_QUERY************/
			/************CTRL_AFTER_QUERY************/
			
			return Protocol.create().setList(result);
		}catch(DefineException e){
			return Protocol.create(false, e.getMessage(), e.getCode());
		}catch(Exception e){		
			e.printStackTrace();
			LoggerHelper.writeError(e);
			return Protocol.create(false,Utils.or(Utils.config("exception.message"), "系统繁忙，请稍后再试"),"exception");
		}
	}
	/************CTRL_DEFINE_CODE************/
	@RequestMapping("/manage/agents/agentconf.dowqrcode.do")
	public Protocol dowqrcode(Long id){
		Protocol protocol = Protocol.create(true, null);
		AgentConf conf=AgentConf.where.id(id).get();
		  WeiXinAccessTokenUtil weiXinAccessTokenUtil=new WeiXinAccessTokenUtil();
	    	String accessToken=weiXinAccessTokenUtil.getWeChatAccessTokens();
	    	String fileName=conf.getId()+"_"+conf.getMerchant()+"_"+new Date().getTime()+".png";
	    	String urlString=WxMiniQrCodeUtil.getMiniCode(conf.getMerchant$(), accessToken,"pages/member/tab3/coupon/couponGet",fileName);
	    	conf.setQrCode(urlString);
	    	conf.update();
    		protocol.set("msg", "生成完成请刷新页面");
    		protocol.set("type", true);
		return protocol;
	}
	/************CTRL_DEFINE_CODE************/
  	
  	/**获取子项列表**/
	public static Map getItems(){
		Map map = new HashMap();
		/************CTRL_DEFINE_ITEMS************/
		/************CTRL_DEFINE_ITEMS************/
		return map;
	}
  	
  	/**
	* 设置排序
	**/
  	private Map<String,Object> setDefaultSort(Map<String, Object> params) {
		String strAsc=AgentConf.C.get(Utils.forMat(Utils.getString("asc")));//升序字段
		params.put("asc", strAsc);//放入查询条件
		String strDesc=AgentConf.C.get(Utils.forMat(Utils.getString("desc")));//降序字段
		params.put("desc",strDesc);//放入查询条件 
		if(Utils.empty(strAsc) && Utils.empty(strDesc))//如果未传入排序字段
			params.put("desc","id");//那么，默认以主键降序，传给Dao层
		return params;
	}
  	/**
	* 设置默认值
	**/
	public void setDefaultValue(AgentConf agentConf,String type){
		if(type.equals("insert")){//添加时			
			if(agentConf.getUpdateTime()==null)
				agentConf.setUpdateTime(new Date());
			if(agentConf.getAddTime()==null)
				agentConf.setAddTime(new Date());
			if(agentConf.getStatus()==null)
				agentConf.setStatus((short)1);
		}else if(type.equals("update")){//编辑时
			agentConf.setUpdateTime(new Date());
		}
	}
	/**
	* 设置表单信息
	**/
	public void setFormDataInfo(Protocol protocol,String edittype,AgentConf agentConf){
		Map model = new HashMap();
		model.put("name","agentConf");
		model.put("caption","代理卡配置");
		model.put("type","table");
		model.put("icon","icon-yinhangka");
		model.put("PK","id");
		model.put("add",true);
		model.put("update",true);
		model.put("details",true);
		List propertys = new ArrayList();
		List submits = new ArrayList();
		model.put("propertys", propertys);
		model.put("submits", submits);	
		protocol.set("model", model);
		if(Utils.empty(edittype)){
		propertys.add(Utils.add("name","status").add("cell","coner").add("caption","状　　态").add("input","select").add("primary",false).add("length",2).add("options",new Object[]{Utils.add("text","正常").add("value","1"),Utils.add("text","无效").add("value","0")}));
		}
		else{
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","name").add("caption","名　　称").add("input","text").add("primary",false).add("length",32).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","products").add("caption","产品配置").add("input","grid").add("primary",false).add("length",1024).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("options",new Object[]{Utils.add("text","commodity").add("value","query").add("depict","商品"),Utils.add("text","number").add("value","number").add("depict","数量"),Utils.add("text","price").add("value","money").add("depict","价格")}));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","price").add("caption","代理卡价格").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","dlZjJl").add("caption","代理直接奖励").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","dlJjJl").add("caption","代理间接奖励").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","fxZjJl").add("caption","分销直接奖励").add("input","menoy").add("primary",false).add("length",8).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","fxJjJl").add("caption","分销间接奖励").add("input","menoy").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","purchase").add("caption","代理政策简述").add("input","textarea").add("primary",false).add("length",256).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","agreement").add("caption","代理协议").add("input","html").add("primary",false).add("length",65535).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"none")).equals("none")){
				propertys.add(Utils.add("name","updateTime").add("caption","修改时间").add("input","datetime").add("primary",false).add("length",19).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"none")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"none")).equals("none")){
				propertys.add(Utils.add("name","addTime").add("caption","添加时间").add("input","datetime").add("primary",false).add("length",19).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"none")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"editable")).equals("none")){
				propertys.add(Utils.add("name","status").add("caption","状　　态").add("input","select").add("primary",false).add("length",2).add("notNull",true).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"none":"editable")).add("options",new Object[]{Utils.add("text","正常").add("value","1"),Utils.add("text","无效").add("value","0")}));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","merchant").add("caption","所属品牌").add("input","query").add("primary",false).add("length",8).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).add("relate","Merchant"));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","policy").add("caption","分销政策").add("input","textarea").add("primary",false).add("length",2000).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","interest").add("caption","权益介绍文字").add("input","textarea").add("primary",false).add("length",256).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			if(!(edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")).equals("none")){
				propertys.add(Utils.add("name","agentcAgentAccessionConditions").add("caption","代理加入条件").add("input","textarea").add("primary",false).add("length",256).add("notNull",false).add("unique",false).add("editable",edittype.equals("details")?"readonly":(edittype.equals("insert")?"editable":"editable")));
			}
			submits.add(Utils.add("name","submiter").add("value","完成").add("title","完成").add("icon","icon-weibiaoti8"));
		}
	}
  
}